import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import "./res/listData.dart";

void main() {
  runApp(
    MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('你好flutter1')),
        body: Padding(
            padding: const EdgeInsets.all(10),
            // wrap 横向布局，超出换行
            child: Wrap(
              // x 轴间距
              spacing: 10,
              // y 轴间距
              runSpacing: 5,
              // 水平排列方式
              alignment: WrapAlignment.spaceAround,
              children: [
                Button('按钮1', onPressed: () {}),
                Button('按钮1', onPressed: () {}),
                Button('按钮1', onPressed: () {}),
                Button('按钮1111', onPressed: () {}),
                Button('按钮1', onPressed: () {}),
                Button('按钮1', onPressed: () {}),
                Button('按钮1', onPressed: () {}),
                Button('按钮11111111', onPressed: () {}),
                Button('按钮1', onPressed: () {}),
                Button('按钮1', onPressed: () {}),
                Button('按钮1', onPressed: () {}),
                Button('按钮1', onPressed: () {}),
                Button('按钮1', onPressed: () {}),
                Button('按钮1', onPressed: () {}),
                Button('按钮1', onPressed: () {}),
              ],
            )),
      ),
    ),
  );
}

// 自定义按钮
class Button extends StatelessWidget {
  String text;
  void Function()? onPressed;
  Button(this.text, {this.onPressed, super.key});

  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
      onPressed: onPressed,
      style: ButtonStyle(
        foregroundColor: MaterialStateProperty.all(Colors.black),
        backgroundColor: MaterialStateProperty.all(
          const Color.fromARGB(255, 182, 180, 174),
        ),
      ),
      child: Text(text),
    );
  }
}
